using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Wicresoft.EKA.VCenter
{
    public class ExtendedAppUtil : AppUtil
    {
        private SvcConnectionV25 _connectionV25;
        private ServiceUtilV25 _svcUtil;
        // Create a logger for use in this class
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static ExtendedAppUtil InitializeV25(String name, OptionSpec[] userOptions)
        {
            ExtendedAppUtil cb = new ExtendedAppUtil(name);
            cb.AddOptions(userOptions);
            cb.Validate();
            return cb;
        }

        public ExtendedAppUtil(String name)
            : base(name)
        {
            Setup(name);
        }

        public void Setup(String name)
        {
            _svcUtil = new ServiceUtilV25();
            _connectionV25 = new SvcConnectionV25("ServiceInstance");
        }
        public override void Connect()
        {
            log.Info("Started ");
            try
            {
                InitConnection();
                ServiceUtilV25.ClientConnect();
            }
            catch (Exception e)
            {
                log.Error("Exception running : ", e);
                Util.LogException(e);
                throw new ArgumentHandlingException("Exception running : "
                                                                       + AppName);
            }
        }
        public void Connect(Cookie cookie)
        {
            log.Info("Started ");
            try
            {
                InitConnection();
                ServiceUtilV25.ClientConnect(cookie);
            }
            catch (Exception e)
            {
                log.Error("Exception running : ", e);
                Util.LogException(e);
                throw new ArgumentHandlingException("Exception running : "
                                                                       + AppName);
            }
        }
        public override void InitConnection()
        {
            ServiceUtilV25.Init(this);
        }

        public ServiceUtilV25 ServiceUtilV25
        {
            get
            {
                return _svcUtil;
            }
        }
        public SvcConnectionV25 ServiceConnectionV25
        {
            get
            {
                return _connectionV25;
            }
        }
        public override void DisConnect()
        {
            log.Info("Ended " + AppName);
            try
            {
                ServiceUtilV25.ClientDisconnect();
            }
            catch (Exception e)
            {
                log.Error("Exception running : ", e);
                Util.LogException(e);
                throw new ArgumentHandlingException("Exception running : "
                                                                       + AppName);
            }
        }
        protected override void Validate()
        {
            base.Validate();
        }
    }
}
